<template>
  <a-modal
    :visible="visible"
    :title="t('create dir')"
    :cancelText="t('cancel')"
    :okText="t('submit')"
    @ok="submit"
    @cancel="cancel(false)"
  >
    <a-form
      ref="formRef"
      :model="formState"
      :rules="formRules"
      :label-col="labelCol"
      :wrapper-col="wrapperCol"
    >
      <a-form-item ref="dirname" :label="t('dirname')" name="dirname"
        ><a-input v-model:value="formState.dirname" />
      </a-form-item> 
    </a-form>
  </a-modal>
</template>
<script>
import { useI18n } from "vue-i18n";
import { message } from "ant-design-vue";
import { createdir } from "@/core/api/module/SysFile";
import { defineComponent, reactive, ref, toRaw, watch } from "vue";
export default defineComponent({
  props: {
    visible: {
      type: Boolean,
    },
    record: {
      type: Object,
    },
  },
  emit: ["close"],
  setup(props, context) {
    const { t } = useI18n();
    const state = reactive({
      depts: [],
      showComponent: true,
      showPath: true,
      showCode: false,
    });

    const formRef = ref();

    let formState = reactive({
      path:props.record,
      dirname:""
    });
 

    const formRules = {
      dirname: [
        {
          required: true,
          message: t("dirname") + t("must input"),
          trigger: "blur",
        },
      ],
    };

    const submit = (e) => {
      formRef.value
        .validate()
        .then(() => {
          createdir(toRaw(formState)).then((response) => {
            if (response.code == 0) {
              message.success({ content: "保存成功", duration: 1 }).then(() => {
                cancel(true);
              });
            } else {
              message.error({ content: response.msg, duration: 1 }).then(() => {
                cancel(false);
              });
            }
          });
        })
        .catch((error) => {
          console.log("error", error);
        });
    };

    const cancel = (e = false) => {
      formRef.value.resetFields();
      context.emit("close", e);
    };

    return {
      t,
      state,
      submit,
      cancel,
      formRef,
      formState,
      formRules,
      labelCol: { span: 6 },
      wrapperCol: { span: 18 },
    };
  },
});
</script>